home *** CD-ROM | disk | FTP | other *** search
/ SGI Developer Toolbox 6.1 / SGI Developer Toolbox 6.1 - Disc 4.iso / src / haeberli / tools / showmap.c < prev    next >
C/C++ Source or Header  |  1994-08-01  |  3KB  |  147 lines

  1. /*
  2.  * Copyright 1991, 1992, 1993, 1994, Silicon Graphics, Inc.
  3.  * All Rights Reserved.
  4.  *
  5.  * This is UNPUBLISHED PROPRIETARY SOURCE CODE of Silicon Graphics, Inc.;
  6.  * the contents of this file may not be disclosed to third parties, copied or
  7.  * duplicated in any form, in whole or in part, without the prior written
  8.  * permission of Silicon Graphics, Inc.
  9.  *
  10.  * RESTRICTED RIGHTS LEGEND:
  11.  * Use, duplication or disclosure by the Government is subject to restrictions
  12.  * as set forth in subdivision (c)(1)(ii) of the Rights in Technical Data
  13.  * and Computer Software clause at DFARS 252.227-7013, and/or in similar or
  14.  * successor clauses in the FAR, DOD or NASA FAR Supplement. Unpublished -
  15.  * rights reserved under the Copyright Laws of the United States.
  16.  */
  17. /*
  18.  *    showmap - 
  19.  *        Display the color map.
  20.  *
  21.  *                Paul Haeberli - 1984
  22.  *
  23.  */
  24. #include <stdio.h>
  25. #include <gl/gl.h>
  26. #include <gl/device.h>
  27.  
  28. main(argc, argv)
  29. int argc;
  30. char **argv;
  31. {
  32.     Device dev;
  33.     short val;
  34.     int shrink = 0;
  35.     int fullconfig = 0;
  36.     int menu, planes;
  37.     int size1, size2, cursize;
  38.  
  39.     if( argc == 2 ) {
  40.     if(strcmp(argv[1],"-s") != 0) {
  41.             fprintf(stderr,"usage: showmap [-s]\n");
  42.             exit(1);
  43.     }
  44.     shrink = 1;
  45.     }
  46.  
  47.     keepaspect(1,1);
  48.     winopen("showmap");
  49.     qdevice(LEFTMOUSE);
  50.     qdevice(MENUBUTTON);
  51.     menu = defpup("showmap %t|makemap|cedit|interp|exit");
  52.     planes = getplanes();
  53.     if (planes<8)
  54.     size1 = size2 = 8;
  55.     else if (planes==8)
  56.     size1 = size2 = 16;
  57.     else if (planes==10)
  58.     size1 = size2 = 32;
  59.     else {
  60.     size1 = 64;
  61.     size2 = 32;
  62.     fullconfig = 1;
  63.     }
  64.     if (shrink && fullconfig)
  65.         cursize = size2;
  66.     else
  67.         cursize = size1; 
  68.     showmap(cursize);
  69.     while (1) {
  70.     int needs_redraw = 0;
  71.     do {
  72.         dev = qread(&val);
  73.         switch(dev) {
  74.         case REDRAW: 
  75.         reshapeviewport();
  76.         needs_redraw = 1;
  77.         break;
  78.         case LEFTMOUSE: 
  79.         if(val) {
  80.             if(cursize==size1)
  81.              cursize=size2;
  82.             else
  83.              cursize=size1;
  84.             needs_redraw = 1;
  85.         }
  86.         break;
  87.         case MENUBUTTON: 
  88.         if (val) {
  89.             switch (dopup(menu)) {
  90.             case 1: 
  91.                 dosystem("makemap");
  92.                 break;
  93.             case 2: 
  94.                 dosystem("cedit");
  95.                 break;
  96.             case 3: 
  97.                 dosystem("interp");
  98.                 break;
  99.             case 4: 
  100.                 exit(0);
  101.             }
  102.         }
  103.         break;
  104.         }
  105.     } while (qtest());
  106.     if (needs_redraw)
  107.         showmap(cursize);
  108.     }
  109. }
  110.  
  111. showmap(cursize)
  112. int cursize;
  113. {
  114.     int i, j, planes;
  115.     long  xsize, ysize;
  116.  
  117.     grey(0.9);
  118.     clear();
  119.     planes = getplanes();
  120.     ortho2(-0.25,cursize+0.25,-0.25,cursize+0.25);
  121.     if(cursize == 8) {
  122.         for (j=0; j<8; j++) {
  123.         for (i=0; i<8; i++) {
  124.             color((j*8)+i);
  125.             rectf(i+0.1,j+0.1,i+0.9,j+0.9);
  126.         }
  127.         }
  128.     } else {
  129.         for (j=0; j<cursize; j++) {
  130.         for (i=0; i<cursize; i++) {
  131.             color((j*cursize)+i);
  132.             rectfi(i,j,i+1,j+1); 
  133.         }    
  134.     }
  135.         grey(0.5);
  136.     getsize(&xsize,&ysize);
  137.     if((xsize/cursize)>4) {
  138.             for (j=0; j<=cursize; j++) {
  139.             move2i(0,j);
  140.             draw2i(cursize,j);
  141.             move2i(j,0);
  142.             draw2i(j,cursize);
  143.             }
  144.     }
  145.     }
  146. }
  147.